package test;

import org.apache.ibatis.session.SqlSession;
import org.example.bean.Student;
import org.example.mapper.StudentMapper;
import org.example.util.SqlSessionUtil;
import org.junit.Test;

import java.util.List;


public class TT02 {


    /**
     * 新增
     */
    @Test
    public void test01(){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        int i = mapper.insertStudent();
        System.out.println(i);

        sqlSession.commit();
    }
    /**
     * 根据id删除
     */
    @Test
    public void test02(){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        int i = mapper.deleteStudentById();
        System.out.println(i);

        sqlSession.commit();
    }

    /**
     * 根据id修改
     */
    @Test
    public void test03(){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        int i = mapper.updateStudentById();
        System.out.println(i);

        sqlSession.commit();
    }
    /**
     * 根据id查询
     */
    @Test
    public void test04(){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        Student student = mapper.selectStudentById();
        System.out.println(student);

        sqlSession.commit();
    }
    /**
     * 查询全部
     */
    @Test
    public void test05(){
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        List<Student> lists = mapper.selectStudentAll();
        for (Student list : lists) {
            System.out.println(list);
        }

        sqlSession.commit();
    }
}
